<?php

namespace Question\Controller;

/**
 * 用户
 */
class Answer extends \App\Application {

	private $_answerService;

	public function __construct($appName, $controllerName, $actionName) {
		parent::__construct($appName, $controllerName, $actionName);
		$this->_answerService = \Lsf\Loader::service('Answer', FALSE, APP_NAME_QUESTION);
	}

	/**
	 * 微信提交答案
	 */
	public function submit() {
		$params = $this->post('', TRUE);
		if (!isset($params['uid']) || empty($params['uid'])) {
			return $this->errParamMissing(ECODE_PARAM_MISSING, 'uid');
		}
		if(!isset($params['point'])) {
			// 公众号答题
			if (!isset($params['question_set_id']) || empty($params['question_set_id'])) {
				return $this->errParamMissing(ECODE_PARAM_MISSING, 'question_set_id');
			}
			if (!isset($params['answer_info']) || empty($params['answer_info'])) {
				return $this->errParamMissing(ECODE_PARAM_MISSING, 'answer_info');
			}
			// 提交答案
			$result = $this->_answerService->checkAnswerVx($params['uid'],$params['question_set_id'],$params['answer_info']);
		}else  {
			// 扫码答题
//			if (!isset($params['no']) || empty($params['no'])) {
//				return $this->errParamMissing(ECODE_PARAM_MISSING, 'no');
//			}
			if (!isset($params['point']) || empty($params['point'])) {
				return $this->errParamMissing(ECODE_PARAM_MISSING, 'point');
			}
			// 提交答案
			$result = $this->_answerService->checkAnswerCode($params['uid'],$params['point']);
		}
		if(!is_array($result) || empty($result)){
			return $this->json(4,[],'提交答案失败');
		}
		return $this->json(ECODE_SUCCESS, $result);
	}
}
